package com.aaa.mrcai.controller;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.aaa.mrcai.pojo.entity.Test;
import com.aaa.mrcai.pojo.entity.TestOne;
import com.aaa.mrcai.pojo.vo.ShopOneSoVO;
import com.aaa.mrcai.pojo.vo.ShopSoVO;
import com.aaa.mrcai.result.AjaxResult;
import com.aaa.mrcai.service.OrderAddService;
import com.aaa.mrcai.service.OrderAddOneService;
import com.aaa.mrcai.service.ZfbTestService;
import com.aaa.mrcai.service.ZfbTestOneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @ Author: Lining
 * @ Date: 2021/12/16 10:17
 */
@RestController
@RequestMapping("pay")
public class ZfbzfController {

    @Autowired
    private ZfbTestService zfbTestService;

    @Autowired
    private ZfbTestOneService zfbTestOneService;

    @Autowired
    private OrderAddService orderAddService;

    @Autowired
    private OrderAddOneService orderAddOneService;


    @RequestMapping("payTest")
    public AjaxResult Zfbtest(Test test, ShopSoVO shopSoVO ){
        //生成一个订单号  当前日期 和一个随机数5位
        String format = DateUtil.format(new Date(),"yyyyMMddHHmmss");
        String numbers = RandomUtil.randomNumbers(5);
        String liushui = format+numbers;

        //给test设置id为订单号
        test.setSoid(liushui);

        //添加一个订单  当前的状态为未支付
        int i = orderAddService.addPendingOrder(test,shopSoVO);

        AjaxResult zfbtest = zfbTestService.zfbtest(test);
        return zfbtest;
    }
    @RequestMapping("queryTest")
    public AjaxResult queryTest(){
       return  zfbTestService.queryTest();
    }

    @RequestMapping("addOrder")
    public AjaxResult addOrder(){
        int i = zfbTestService.addOrder();
        if (i>0){
            return  AjaxResult.success("订单创建成功");
        }
        return AjaxResult.defeated("订单创建失败");
    }

    @RequestMapping("payTestOne")
    public AjaxResult ZfbtestOne(TestOne testone){
        System.out.println(testone.getTotalPrice()+"888888");
        //生成一个订单号  当前日期 和一个随机数5位
        String format = DateUtil.format(new Date(),"yyyyMMddHHmmss");
        String numbers = RandomUtil.randomNumbers(5);
        String liushui = format+numbers;

        //给test设置id为订单号
        testone.setSoid(liushui);

        //添加一个订单  当前的状态为未支付
        int i = orderAddOneService.addPendingOrderOne(testone);

        AjaxResult zfbtestOne = zfbTestOneService.zfbtestOne(testone);
        return zfbtestOne;
    }
    @RequestMapping("payTestOneOrder")
    public AjaxResult payTestOneOrder(ShopOneSoVO shopOneSoVO){
        int i = orderAddOneService.addOneGoodInOrderOne(shopOneSoVO);
        return AjaxResult.success(i);
    }

    @RequestMapping("queryTestOne")
    public AjaxResult queryTestOne(){
        return  zfbTestOneService.queryTestOne();
    }

    @RequestMapping("addOrderOne")
    public AjaxResult addOrderOne(){
        int i = zfbTestOneService.addOrderOne();
        if (i>0){
            return  AjaxResult.success("订单创建成功");
        }
        return AjaxResult.defeated("订单创建失败");
    }

//    @RequestMapping("inventory")
//    public AjaxResult inventory(ShopOneSoVO  shopOneSoVO){
//        return  orderAddOneService.inventory(shopOneSoVO);
//    }

}
